<?php 
require_once("../include/conn.php");
//$buname=trim($_REQUEST["buname"]);
	
		if($_REQUEST["action"] == "update")
		{	
			
				if(!empty($_REQUEST["id"]) and !empty($_REQUEST["buname"]))
				{
			
					$id=$_REQUEST["id"];
					$name=$_REQUEST["name"];
					$benid=$_REQUEST["benid"];
					$benindex=$_REQUEST["benindex"];
					$pp=split("&isindex=",$name);
					print_r($pp);
					$namep=$pp[0];
					
					if($namep==0){
						$isindex=1;
						$parentid=0;
					}else{
						
						if($pp[1]<3){
							$isindex=$pp[1]+1;						
							}
						$parentid=$namep;
					}
					
					$buname=$_REQUEST["buname"];
					$sql_dz="UPDATE `$tb_bm` SET  `buname` = '".$buname;
					
					
					if($benid==$namep && $pp[1]==$benindex)
					{
						//什么也不做	
					}else{
						$sql_dz.="' ,`isindex` = '$isindex' ,`parentid` = '".$parentid;
					}					
					$sql_dz.="'  WHERE  `id` = '$id'";
					
					echo  $sql_dz;
					$cn_dz = mysql_db_query($db_name,$sql_dz); 
					
					self("操作已成功!","lanmu_mange.php");
				}else{
		
				self("参数不全!","lanmu_mange.php");
				
				}
		
		}
		elseif($_REQUEST["action"] == "add")
		{	
		
			if(!empty($_REQUEST["buname"])){
				$fieldnum="`buname`";
				
				$contentnum="'$buname'";
				
				$name=$_REQUEST["name"];
				$pp=split("&isindex=",$name);
				//print_r($pp);
				$namep=$pp[0];
				
				if($namep==0){
					$isindex=1;
					$parentid=0;
				}else{
					
					$isindex=$pp[1]+1;						
					$parentid=$namep;
				}
				
					$fieldnum.=", `isindex`, `parentid` ";			
					$contentnum.=", '".$isindex."', '".$parentid."'";				
								
				$sql_add="INSERT INTO $tb_bm( ".$fieldnum.")  VALUES (".$contentnum.")";
				
				//echo $sql_add;				
				
				$cn_add = mysql_query($sql_add);
				//$id = mysql_insert_id();
			
				self("操作已成功!","lanmu_mange.php");
			
			}else{				
				self("参数不全!","lanmu_mange.php");
				}
		}
		
		elseif($_REQUEST["action"] == "delete")
		{	
		
			if(!empty($_REQUEST["id"])){
				
				$id=$_REQUEST["id"];
							
								
				$sql_add="delete from  $tb_bm  where id= ".$id;
				
				//echo $sql_add;				
				
				$cn_add = mysql_query($sql_add);
				//$id = mysql_insert_id();
			
				self("操作已成功!","lanmu_mange.php");
			
			}else{				
				self("参数不全!","lanmu_mange.php");
				}
		}			
		//echo $nname;	
		?>
		